import java.util.Random;
import java.util.Scanner;

public class AppleGame {
    public static void main(String[] args) {
        int gold = 10;
        int winamount = 0;
        int rand;
        int unit=0;
        String luckyid="";
        Scanner sc = new Scanner(System.in);
        while (gold > 0) {
            System.out.println("您当前金币总计￥" + gold);//显示金币数
            System.out.println("欢迎进入游戏，新的一轮游戏马上开始！");
            System.out.println("猜中的物品和对应的奖励系数如下：");
            System.out.println("苹果-------2倍 ");
            System.out.println("木瓜-------5倍 ");
            System.out.println("西瓜-------10倍 ");
            System.out.println("香蕉-------20倍 ");
            System.out.println("橙子-------50倍 ");
            System.out.println("葡萄-------100倍 ");
            System.out.println("游戏结束，请按Q");
            System.out.println("请选择水果（苹果/木瓜/西瓜/香蕉/橙子/葡萄）:");
            String fruit = sc.next();//获取水果
            if (fruit.equals("Q")) {
                break;
            }
            System.out.println("请输入你要押的金币(最多）" + gold + "金币");
            int amount;
            do {
                if (!sc.hasNextInt()) {
                    System.out.println("输入无效，请输入一个整数：");
                    sc.nextLine(); // 清除无效输入
                } else {
                    amount = sc.nextInt();
                    if (amount <= 0 || amount > gold) {
                        System.out.println("押注无效,请重新输入");
                    } else {
                        break; // 输入有效，跳出循环
                    }
                }
            } while (true);
            System.out.println("幸运苹果机开始运转------Good Luck\n");
            rand=(int)(Math.random()*10);//获得随机数.random()产生数据的范围
            switch(rand){
                case 1: System.out.println("----苹果----"); luckyid="苹果";unit=2;break;
                case 2: System.out.println("----木瓜----"); luckyid="木瓜";unit=5;break;
                case 3: System.out.println("----西瓜----"); luckyid="西瓜";unit=10;break;
                case 4: System.out.println("----香蕉----"); luckyid="香蕉";unit=20;break;
                case 5: System.out.println("----橙子----"); luckyid="橙子";unit=50;break;
                case 6: System.out.println("----葡萄----"); luckyid="葡萄";unit=100;break;
                default : System.out.println("----水果盘---");luckyid="水果盘";
            }

            System.out.println("随机选中的水果为：" + luckyid);
            if (fruit.equals(luckyid)) {//检查是否中奖
                winamount=amount*unit;
                System.out.println("恭喜，您中奖了！您获得了" + winamount + "个金币");
                gold = gold + winamount;

            } else {
                System.out.println("很遗憾，您没有猜对，您损失了" + amount + "金币");
                gold = gold - amount;
            }
            System.out.println("--------本轮游戏结束--------");
            String kongge = sc.nextLine();
        }
        if (gold <= 0) {
            System.out.println("您的金币已经用完，游戏结束!");

        }
    }
}
